﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using DataStore.Domain;
using System.Windows.Input;
using Microsoft.Practices.Composite.Events;

namespace Infrastructure.ViewModels
{
    public class AddressViewModel : DataModelSingle<Address>, IDataErrorInfo
    {
        public AddressViewModel(Address address) : base(address)
        {}

        public AddressViewModel(IEventAggregator eventAggregator, Address address)
            : base(eventAggregator, address)
        {

        }

        public virtual Guid Id 
        {
            get
            {
                return Item.Id;
            }
            set
            {
                if (Item.Id != value)
                {
                    Item.Id = value;
                    OnPropertyChanged("Id");
                }
            }
        }
        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        /// <value>The description.</value>
        public virtual string Description 
        {
            get
            {
                return Item.Description;
            }
            set
            {
                if (Item.Description == value)
                {
                    Item.Description = value;
                    OnPropertyChanged("Description");
                }
            } 
        }
        /// <summary>
        /// Gets or sets the street.
        /// </summary>
        /// <value>The street.</value>
        public virtual string Street 
        {
            get
            {
                return Item.Street;
            }
            set
            {
                if (Item.Street == value)
                {
                    Item.Street = value;
                    OnPropertyChanged("Street");
                }
            } 
        }
        /// <summary>
        /// Gets or sets the district.
        /// </summary>
        /// <value>The district.</value>
        public virtual string District
        {
            get
            {
                return Item.District;
            }
            set
            {
                if (Item.District == value)
                {
                    Item.District = value;
                    OnPropertyChanged("District");
                }
            } 
        }
        /// <summary>
        /// Gets or sets the city.
        /// </summary>
        /// <value>The city.</value>
        public virtual string City
        {
            get
            {
                return Item.City;
            }
            set
            {
                if (Item.City == value)
                {
                    Item.City = value;
                    OnPropertyChanged("City");
                }
            } 
        }
        /// <summary>
        /// Gets or sets the county.
        /// </summary>
        /// <value>The county.</value>
        public virtual string County
        {
            get
            {
                return Item.County;
            }
            set
            {
                if (Item.County == value)
                {
                    Item.County = value;
                    OnPropertyChanged("County");
                }
            } 
        }
        /// <summary>
        /// Gets or sets the postal code.
        /// </summary>
        /// <value>The postal code.</value>
        public virtual string PostalCode
        {
            get
            {
                return Item.PostalCode;
            }
            set
            {
                if (Item.PostalCode == value)
                {
                    Item.PostalCode = value;
                    OnPropertyChanged("PostalCode");
                }
            } 
        }
        /// <summary>
        /// Gets or sets the complements.
        /// </summary>
        /// <value>The complements.</value>
        public virtual string Complements
        {
            get
            {
                return Item.Complements;
            }
            set
            {
                if (Item.Complements == value)
                {
                    Item.Complements = value;
                    OnPropertyChanged("Complements");
                }
            } 
        }
        /// <summary>
        /// Gets or sets the neighbourhood.
        /// </summary>
        /// <value>The neighbourhood.</value>
        public virtual string Neighbourhood
        {
            get
            {
                return Item.Neighbourhood;
            }
            set
            {
                if (Item.Neighbourhood == value)
                {
                    Item.Neighbourhood = value;
                    OnPropertyChanged("Neighbourhood");
                }
            } 
        }
        /// <summary>
        /// Gets or sets the municipality.
        /// </summary>
        /// <value>The municipality.</value>
        public virtual string Municipality
        {
            get
            {
                return Item.Municipality;
            }
            set
            {
                if (Item.Municipality == value)
                {
                    Item.Municipality = value;
                    OnPropertyChanged("Municipality");
                }
            } 
        }
        /// <summary>
        /// Gets or sets the state.
        /// </summary>
        /// <value>The state.</value>
        public virtual string State
        {
            get
            {
                return Item.State;
            }
            set
            {
                if (Item.State == value)
                {
                    Item.State = value;
                    OnPropertyChanged("State");
                }
            } 
        }
        /// <summary>
        /// Gets or sets the apartment.
        /// </summary>
        /// <value>The apartment.</value>
        public virtual string Apartment
        {
            get
            {
                return Item.Apartment;
            }
            set
            {
                if (Item.Apartment == value)
                {
                    Item.Apartment = value;
                    OnPropertyChanged("Apartment");
                }
            } 
        }
        /// <summary>
        /// Gets or sets the country.
        /// </summary>
        /// <value>The country.</value>
        public virtual Country Country
        {
            get
            {
                return Item.Country;
            }
            set
            {
                if (Item.Country == value)
                {
                    Item.Country = value;
                    OnPropertyChanged("Country");
                }
            } 
        }

        /// <summary>
        /// Gets an error message indicating what is wrong with this object.
        /// </summary>
        /// <value></value>
        /// <returns>An error message indicating what is wrong with this object. The default is an empty string ("").</returns>
        public string Error
        {
            get { return (Item as IDataErrorInfo).Error; }
        }

        /// <summary>
        /// Gets the <see cref="System.String"/> with the specified column name.
        /// </summary>
        /// <value></value>
        public string this[string columnName]
        {
            get
            {
                string error = string.Empty;
                error = (Item as IDataErrorInfo)[columnName];

                CommandManager.InvalidateRequerySuggested();
                return error;
            }
        }
    }
}
